package com.download.web.service.impl;

import com.download.web.entity.BusBuy;
import com.download.web.mapper.BusBuyMapper;
import com.download.web.service.BusBuyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class BusBuyServiceImpl implements BusBuyService {

    @Resource
    private BusBuyMapper busBuyMapper;

    @Override
    public Map<String,Object> selectAll(String startTime, String endTime, int page, int limit) {
        try {
            Map<String,Object> map=new HashMap<>();
            StringBuffer sb=new StringBuffer("");
            if(startTime!=null&&!startTime.equals("")){
                sb.append(" AND b.time>='"+startTime+"' ");
            }
            if(endTime!=null&&!endTime.equals("")){
                sb.append(" AND b.time<='"+endTime+"'");
            }
            List<Map<String,Object>> list=busBuyMapper.selectAll(sb.toString(),(page-1)*limit,limit);
            int count=busBuyMapper.selectAllCount(sb.toString());
            map.put("data",list);
            map.put("totalCount",count);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            map.put("page",page);
            map.put("limit",limit);
            return map;
        } catch (Exception e){
            e.printStackTrace();
            return  null;
        }
    }
}
